import {Component, OnInit,HostListener,Inject,Renderer} from '@angular/core';
import { Router,Event,NavigationEnd,NavigationStart }  from '@angular/router';
import { BackMenuService} from "../service/back-menu.service";
import { User } from '../model/user-model';
import { GlobalVariable} from "../global.config";
import { DOCUMENT } from '@angular/platform-browser';


//import {GoTopButtonModule} from 'ng2-go-top-button';
//import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
declare var $:any;


@Component({
  selector: 'app-page',
  templateUrl: './page.component.html',
  styleUrls: ['./page.component.css'],
  
})

export class PageComponent implements OnInit {
  isLogin:any;
  isOpen:boolean = false;
  head_img:string;
  uname:string;
  app = GlobalVariable.app;
  menus: any = [];
  url:string = '';
  backMenus:any = []; 
  state:boolean = true;
  mystate:number = 1;
  username = localStorage.getItem('username');
  constructor(
              private backMenuService:BackMenuService,
              private _router: Router) {  
 
    this.menus = {
    path:'page',
    children:[
      {
        path:'dashboard',
        title:'概览',
        cls:'fa fa-dashboard icon',
        active:false,
        index:true,
        order:0

      },
      {
        path: 'usermanagement',       
        title: '用户管理',
        cls: 'fa fa-user',       
        order: 300,        
        children: [
          {
            path: 'generalusers',
            title: '普通用户'              
          }
          // {
          //   path: 'maintenanceusers',
          //   title: '维保用户'
          // },
          // {
          //   path: 'channelusers',
          //   title: '渠道商用户'
          // },
          // {
          //   path: 'channelmaintenanceusers',
          //   title: '渠道商维保用户'
          // },
          // {
          //   path: 'adminusers',
          //   title: '管理员用户'
          // }
        ]
      },                
      // {
      //   path: 'accountfundsmanagement',
      //   title: '账户资金管理',
      //   cls: 'fa fa-money',
      //   order: 300,
      //   children: [
      //     {
      //       path: 'useraccount',
      //       title: '用户账户管理',
            
      //     },
      //     {
      //       path: 'channelaccount',
      //       title: '渠道商账户管理'
             
      //     },
      //     {
      //       path: 'deviceaccount',           
      //       title: '设备账户管理'            
      //     }
      //   ]
      // },
      {
        path: 'ordermanagement',    
        title: '订单管理',
        cls: 'fa fa-list',
        order: 300,
        children: [
          {
            path: 'ordinaryorder',
            title: '普通用户订单'            
          }
          // {
          //   path: 'channelorder',
          //   title: '渠道用户订单'            
          // }
        ]
      }, 
      {
        path:'member',
        title:'加盟商管理',
        cls:'fa fa-id-card-o icon',
        active:false,
        index:true,
        order:0
      },     
      
      {
        path: 'productmanagement',
        title: '产品管理',
        cls: 'fa fa-tasks', 
        children: [
          {
            path: 'devices',            
            title: '设备管理',
             
          }
          // {
          //   path: 'fault',
           
          //   title: '故障工单',
            
          // },
          // {
          //   path: 'maintenance',
          //   title: '维保工单',
          // }
        ]
      },  
      {
        path:'groupmanagement',
        title:'群组管理',
        cls:'fa fa-american-sign-language-interpreting icon',       
        order:300,
        children:[
          {
            path: 'grouplist',
            title: '群组列表'            
          }
        ]

      },
      {
        path:'operation',
        title:'运维管理',
        cls:'fa fa-link icon',       
        order:300,
        children:[
          {
            path: 'operationlist',
            title: '资费策略'            
          }
        ]

      },   
      {
        path: 'sysmanagement',        
        title: '系统管理',
        cls: 'fa fa-cog',       
        order: 300,        
        children: [
          {
            path: 'competence',           
            title: '权限设置',             
          },
          {
            path: 'product',           
            title: '产品设置'             
          }
        ]
      }
    ]
  }

    //返回菜單
    this._router.events.subscribe((val:Event) => {
      if(val instanceof NavigationEnd ){
        this.backMenus = backMenuService.getBackMenu(val.url);
      }

    });
  }


  ngOnInit(){
    this.head_img='assets/img/b9.jpg';
} 






  logout(){    
    localStorage.clear();
    this._router.navigateByUrl('/login');
  }

  selectMenu(idx:any):void{

    for(let i in this.menus.children){
      if(idx != i) this.menus.children[i].active = false;
    }
    this.menus.children[idx].active = !this.menus.children[idx].active;
  }

  Open():void{
    this.isOpen = this.isOpen==false?true:false;
  }

  hideNaviBar(){
    if(this.state == true){
      this.state = false;
    }else{
      this.state = true;
    }
  }


}
